from fastapi import APIRouter, Request
from pydantic import BaseModel, EmailStr
from typing import Union

app7 = APIRouter()


class UserIn(BaseModel):
    username: str
    password: str
    email: Union[EmailStr, None] = None
    full_name: Union[str, None] = None


class UserOut(BaseModel):
    username: str
    email: Union[EmailStr, None] = None
    full_name: Union[str, None] = None


class Item(BaseModel):
    name: str
    description: Union[str, None] = None
    price: float
    tax: float = 10.5
    tags: list[str] = []


# Item示例
items = {
    "foo": {
        "name": "Foo",
        "price": 50.2
    },
    "bar": {
        "name": "Bar",
        "price": 62,
        "description": "The bartenders"
    },
    "bax": {
        "name": "Bax",
        "price": 50.2,
        "description": "Bax does not have a price",
        "tags": ['apple', 'banana', 'orange', 'pear']
    }
}


@app7.post("/user", response_model=UserOut)
async def create_user(user: UserIn):
    # 存到数据库
    return user


@app7.post("/items/{item_id}", response_model=Item, response_model_include={"name", "price"})
async def create_user(item_id: str):
    # 存到数据库
    return items[item_id]
